package com.kx.forum.controller;

import com.kx.base.controller.BaseController;
import com.kx.base.result.R;
import com.kx.forum.dto.CreateForumDTO;
import com.kx.forum.service.ForumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Sun
 * @date 2021/8/9 9:13
 */
@RequestMapping("kx/forum")
@RestController
public class ForumController extends BaseController {

    @Autowired
    private ForumService forumService;

    @PostMapping("create")
    public R createForum(@RequestBody CreateForumDTO createForumDTO) {
        Long userId = userId();
        String title = createForumDTO.getTitle();
        String content = createForumDTO.getContent();
        Integer imageCount = createForumDTO.getImageCount();
        List<String> images = createForumDTO.getImages();
        String video = createForumDTO.getVideo();
        int result = forumService.createForum(userId,title,content,images,imageCount,video);
        if (result==0){
            return R.error(500,"发帖失败");
        }else {
            return R.ok(200,"发帖成功");
        }
    }
}
